home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / cwkgraph.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-30  |  24.8 KB  |  935 lines

  1.  
  2.  
  3. /*
  4.     GWMON Parallel Ada Monitor for 386/486 PCs   
  5.     Copyright (C) 1993, Charles W. Kann  & Michael Bliss Feldman
  6.                         ckann@seas.gwu.edu mfeldman@seas.gwu.edu
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. */
  22.  
  23. #include "ed.h"
  24. #include "keydef.h"
  25.  
  26. #if 0
  27. #define ROWS 10
  28. #endif
  29. static int ROWS = 10;
  30. #define COLS 78
  31. #define MAX_WINDOWS 12
  32. static char video[4000];
  33. static AVL_WIN_PTR  top_win, output_win;
  34. static struct rccoord text_pos;
  35. static int next_monitor;
  36. static int SAVE_WIN_SIZE;
  37.  
  38. /*
  39.    Structures for Block names for monitor windows titles.  Note that the
  40.    Block names structure does not malloc the names.  I was afraid that
  41.    malloc would fragment core too much with alot of funny sized pieces of
  42.    memory.
  43. */
  44.  
  45. #define MAX_LEVELS 200
  46. #define NAME_SIZE 32
  47. static char Block_Name[MAX_LEVELS][NAME_SIZE];
  48.  
  49. #define NEWLINE 0x0a
  50. #define ESCAPE 0x1b
  51.  
  52. void CWK_DEL_WINDOW();
  53. static struct {
  54.     AVL_WIN_PTR w;
  55.     int used;
  56.     COORD wind_coord;
  57.     int monitor;
  58. } window[MAX_WINDOWS];
  59.     
  60. static int SCROLL_LINE = 0, escape_sequence = 0;
  61.  
  62. void CWK_ERASE_ALL_MON_WIN();
  63. void CWK_ERASE_MON_WIN();
  64. void CWK_CLEANUP_MON();
  65.  
  66. CWK_MOVE_INPUT( fp )
  67. FILE *fp;
  68. {
  69.     struct rccoord text_p;
  70.     if ( ! isatty( fileno(fp) )) 
  71.     return;
  72.  
  73.  
  74.     text_p= _gettextposition();
  75.     text_p.col = 1;
  76.     text_p.row++;
  77.     if (text_p.row >= ROWS) {
  78.         SCROLL_LINE = 1;
  79.     text_p.row--;
  80.         }
  81.     _settextposition(text_p.row, text_p.col);
  82. }
  83.  
  84. CWK_PUTC( inchar, fp )
  85. int inchar;
  86. FILE *fp;
  87. {
  88.     struct rccoord text_p;
  89.     static int screen_row, screen_col;
  90.     static char next_char;
  91.     char TextString[2];
  92.  
  93.     /*
  94.     if this file is not a tty, write the character and continue
  95.     */
  96.  
  97.     if ( ! isatty( fileno(fp) )) {
  98.     fputc(inchar,fp);fflush(fp);
  99.     return;
  100.      }
  101.  
  102.  
  103.     /*
  104.     Cheap kludge to handle ascii control sequences
  105.     */
  106.  
  107.     if ( escape_sequence ) {
  108.     switch ( next_char ) {
  109.        case '[' :
  110.         if ( inchar == '[' ) {
  111.             next_char = '1';
  112.             return;
  113.         }
  114.         break;
  115.        case '1' :
  116.         if ( inchar == 'J' ) {
  117.             int i;
  118.             char buf[80];
  119.  
  120.             escape_sequence = 0;
  121.             sprintf(buf,"%-78s"," ");
  122.             for(i = 1; i <= ROWS; ++i) {
  123.                 _settextposition(i, 1 );
  124.                 _outtext(buf);
  125.             }
  126.             _settextposition(1, 1 );
  127.             return;
  128.         }
  129.         else if ( inchar == ';' ) {
  130.             next_char = '2';
  131.             return;
  132.         }
  133.         else if (isdigit( inchar )) {
  134.             screen_row = screen_row * 10 + (inchar - '0');
  135.             return;
  136.         }
  137.         break;
  138.         case '2' :
  139.         if ( inchar == 'f' ) {
  140.             escape_sequence = 0;
  141.                 _settextposition(screen_row, screen_col);
  142.             return;
  143.         }
  144.         else if ( isdigit( inchar )) {
  145.             screen_col = screen_col * 10 + (inchar - '0');
  146.             return;
  147.         }
  148.         break;
  149.         default:
  150.         break;
  151.     }
  152.     escape_sequence = 0;
  153.     }
  154.  
  155.     if ( inchar != ESCAPE ) {
  156.         text_p= _gettextposition();
  157.         if ( SCROLL_LINE ) {
  158.             _scrolltextwindow(_GSCROLLUP);
  159.         SCROLL_LINE = 0;
  160.             }
  161.     }
  162.  
  163.     if ( inchar == ESCAPE ) {
  164.     SCROLL_LINE = 0;
  165.     escape_sequence = 1;
  166.     screen_row = screen_col = 0;
  167.     next_char = '[';
  168.     return;
  169.     }
  170.  
  171.     else if ( ( inchar == NEWLINE ) || ( inchar == CTRL_M ) ) {
  172.     text_p.col = 1;
  173.     text_p.row++;
  174.         if (text_p.row >= ROWS) {
  175.             SCROLL_LINE = 1;
  176.         text_p.row--;
  177.             }
  178.         }
  179.     else {
  180.         sprintf( TextString, "%c", inchar );
  181.         _outtext( TextString );
  182.         text_p.col++;
  183.     if (  text_p.col > COLS ) {
  184.         text_p.col = 1;
  185.         text_p.row++;
  186.         }
  187.     }
  188.     if (text_p.row >= ROWS) {
  189.         SCROLL_LINE = 1;
  190.     text_p.row--;
  191.         }
  192.     _settextposition(text_p.row, text_p.col);
  193. }
  194.  
  195. static int CWK_MON_GET_WIN(monitor)
  196. int monitor;
  197. {
  198.     int i;
  199.     static int last_used;
  200.     
  201.     for (i = 0; i < Windows_Used; i++) {
  202.         if ( ! window[i].used ) {
  203.         window[i].used = 1;
  204.         window[i].monitor = monitor;
  205.         last_used = i;
  206.         return i;
  207.         }
  208.         }
  209.     return -1;
  210.     
  211. }
  212.  
  213. static void CWK_MAKE_WINDOW(title, win_no)
  214. char *title;
  215. int win_no;
  216. {
  217.     window[win_no].w = AVL_MAKE_WINDOW( title, window[win_no].wind_coord.x1,
  218.                 window[win_no].wind_coord.y1, 
  219.                 window[win_no].wind_coord.x2, 
  220.                 window[win_no].wind_coord.y2, 
  221.                 1, 15 );
  222. }
  223.  
  224. static void CWK_SAVE_TEXT_POS()
  225. {
  226.     text_pos = _gettextposition();
  227. }
  228.     
  229. static void CWK_RES_TEXT_POS()
  230. {
  231.     _settextwindow(2,2,ROWS,79);
  232.     _settextposition(text_pos.row, text_pos.col);
  233. }
  234.  
  235. MON_REC_PTR CWK_CREATE_MON_WIN( title, display )
  236. char *title;
  237. int display;
  238. {
  239.     CWK_SAVE_TEXT_POS();
  240.     CWK_MONS[next_monitor].title = malloc( strlen( title ) + 1 );
  241.     strcpy( CWK_MONS[next_monitor].title, title );
  242.     if ( display )
  243.     {
  244.         CWK_MONS[next_monitor].mon_win = CWK_MON_GET_WIN(next_monitor);
  245.         if (CWK_MONS[next_monitor].mon_win == -1)
  246.         {
  247.         CWK_MONS[next_monitor].WON = -1;
  248.         }
  249.         else
  250.         {
  251.         CWK_MONS[next_monitor].WON = 1;
  252.         CWK_MAKE_WINDOW( title, CWK_MONS[next_monitor].mon_win );
  253.         }
  254.     }
  255.     else
  256.         CWK_MONS[next_monitor].WON = -1;
  257.  
  258.     CWK_RES_TEXT_POS();
  259.     return &CWK_MONS[next_monitor++];
  260. }
  261.  
  262. /*************************************************************************/
  263. /*    Routines to draw the monitor windows                             */
  264. /*************************************************************************/
  265. void CWK_REMOVE_BLOCK ( tmp_mon )
  266. MON_REC *tmp_mon;
  267. {
  268.     CWK_SAVE_TEXT_POS();
  269.  
  270.     CWK_ERASE_MON_WIN(tmp_mon);
  271.  
  272.      Block_Level--;
  273.      if ( Block_Level < 0 )
  274.      {
  275.         char msg[80];
  276.             sprintf( msg, "Internal Error, leaving too many blocks" );
  277.         CWK_CLEANUP_MON( -1, msg );
  278.     }
  279.     *Block_Name[Block_Level] = '\0';
  280.     CWK_RES_TEXT_POS();
  281. }
  282.  
  283. void CWK_DRAW_PROC_WIN( tmp_mon, enter_or_exit )
  284. MON_REC *tmp_mon;
  285. int enter_or_exit;
  286. {
  287.     int i, First_Win_On_Screen;
  288.  
  289.     CWK_SAVE_TEXT_POS();
  290.  
  291.     if ( ! enter_or_exit )
  292.     {
  293.         strcpy( Block_Name[Block_Level], tmp_mon->title );
  294.         Block_Level++;  
  295.     }
  296.     
  297.  
  298.     if ( Block_Level >= Windows_Used )
  299.     {
  300.         WIN_SIZE = SAVE_WIN_SIZE - Windows_Used;
  301.         tmp_mon->mon_win = Windows_Used - 1;
  302.         First_Win_On_Screen = Block_Level - Windows_Used;
  303.         CWK_ERASE_ALL_MON_WIN();
  304.         tmp_mon->WON = 1;
  305.         for ( i = 0; i < Windows_Used; ++i )
  306.         {
  307.         window[i].used = 1;
  308.             CWK_MAKE_WINDOW( Block_Name[First_Win_On_Screen+i], i );
  309.         }
  310.     }
  311.     else if ( Block_Level > 0 )
  312.     {
  313.         WIN_SIZE = SAVE_WIN_SIZE - Block_Level;
  314.         tmp_mon->mon_win = Block_Level - 1;
  315.         if ( enter_or_exit )
  316.             CWK_ERASE_MON_WIN(tmp_mon);
  317.         window[Block_Level-1].used = 1;
  318.         tmp_mon->WON = 1;
  319.         CWK_MAKE_WINDOW( Block_Name[Block_Level-1], Block_Level-1);
  320.     }
  321.  
  322.     CWK_RES_TEXT_POS();
  323.  
  324.     /*
  325.         Note that we have to redraw the time, otherwise it
  326.         doesn't look right.
  327.     */
  328.     CWK_REPORT_TIME(Run_Total_Time);
  329. }
  330.  
  331. void CWK_DRAW_MON_WIN(tmp_mon)
  332. MON_REC   *tmp_mon;
  333. {
  334.     CWK_SAVE_TEXT_POS();
  335.     tmp_mon->mon_win = CWK_MON_GET_WIN(next_monitor);
  336.     if (tmp_mon->mon_win == -1)
  337.     {
  338.         tmp_mon->WON = -1;
  339.     }
  340.     else
  341.     {
  342.         tmp_mon->WON = 1;
  343.         CWK_MAKE_WINDOW( tmp_mon->title, tmp_mon->mon_win );
  344.     }
  345.     CWK_RES_TEXT_POS();
  346.  
  347. void CWK_ERASE_ALL_MON_WIN()
  348. {
  349.     int i;
  350.     CWK_SAVE_TEXT_POS();
  351.     for (i = MAX_WINDOWS - 1; i >= 0; i--) {
  352.         if ( window[i].used ) {
  353.         window[i].used = 0;
  354.         window[i].monitor = -1;
  355.         CWK_DEL_WINDOW(i); 
  356.         }
  357.         }
  358.     CWK_RES_TEXT_POS();
  359. }
  360.  
  361. void CWK_ERASE_MON_WIN(tmp_mon)
  362. MON_REC   *tmp_mon;
  363. {
  364. #if 0
  365.     {
  366.     char msg[80];
  367.     sprintf( msg, " in erase_mon_win, name = %s, used =%d\n", 
  368.         tmp_mon->title, window[tmp_mon->mon_win].used );
  369.     _outtext(msg);
  370.     getch();
  371.     }
  372. #endif
  373.     if ( window[tmp_mon->mon_win].used ) 
  374.     {
  375.         CWK_SAVE_TEXT_POS();
  376.         window[tmp_mon->mon_win].used = 0;
  377.         window[tmp_mon->mon_win].monitor = -1;
  378.         CWK_DEL_WINDOW(tmp_mon->mon_win);
  379.         CWK_RES_TEXT_POS();
  380.     }
  381. }
  382.  
  383. void CWK_DEL_MON_WIN(tmp_mon)
  384. MON_REC   *tmp_mon;
  385. {
  386.     CWK_SAVE_TEXT_POS();
  387.     free( CWK_MONS[next_monitor].title );
  388.     window[tmp_mon->mon_win].used = 0;
  389.     tmp_mon->WON = -1;
  390.     CWK_DEL_WINDOW(tmp_mon->mon_win);
  391.     CWK_RES_TEXT_POS();
  392. }
  393.  
  394. void CWK_INIT_MON()
  395. {
  396.     int i;
  397.     char buf[80];
  398.  
  399.         _settextrows( 25 );
  400.         _clearscreen( _GCLEARSCREEN );
  401.  
  402.     top_win = AVL_MAKE_WINDOW( "", 1, 1, 24, 80, 1, 15 );
  403.     output_win = AVL_MAKE_WINDOW( " GWU ADA MONITOR - Type Ctrl h for help, ESC to leave", 1, 1, ROWS+1, 80, 1, 15 );
  404.  
  405.     /*  make the rest of the screen Blue so it looks ok  */
  406.  
  407.     _settextwindow(ROWS+2,1,24,80);
  408.     _setbkcolor( 1 );
  409.     _settextcolor( 15 );
  410.     sprintf( buf, "%80.80s", " " );
  411.     for(i = 1; i < 25 - (ROWS - 2); ++i) {
  412.         _settextposition(i, 1 );
  413.         _outtext(buf);
  414.         }
  415.     
  416.     _settextrows(11);
  417.     _settextwindow(2,2,ROWS,79);
  418.     _settextposition(1,1);
  419.     next_monitor = 0;
  420. }
  421.  
  422. /*
  423. */
  424.  
  425. void CWK_CLEANUP_MON(status, msg)
  426. int status;
  427. char *msg;
  428. {
  429.     AVL_WIN_PTR w;
  430.     int ch;
  431.  
  432.     w = AVL_MAKE_WINDOW( "", 4,15,9,76, 1, 15);
  433.         _settextposition(1, 1);
  434.     if ( status < 0 )
  435.     {
  436.             _outtext(msg);
  437.         ch = getch();
  438.         AVL_DEL_WINDOW( w );
  439.         AVL_DEL_WINDOW( top_win );
  440.         exit(status);
  441.     }
  442.     else if ( status )
  443.             _outtext("Do you wish to Exit (y/n)");
  444.     else
  445.     {
  446.             _outtext("Execution completed");
  447.         ch = getch();
  448.         AVL_DEL_WINDOW( w );
  449.         AVL_DEL_WINDOW( top_win );
  450.         exit(status);
  451.     }
  452.     ch = getch();
  453.     AVL_DEL_WINDOW( w );
  454.     if (( ch == 'y') ||  (ch == 'Y')) {
  455.         AVL_DEL_WINDOW( top_win );
  456.         exit(status);
  457.     }
  458. }
  459.  
  460. void CWK_WRITE_LINE( MON, line, text_line )
  461. MON_REC_PTR MON;
  462. int line;
  463. char *text_line;
  464. {
  465.     if ( MON->WON == -1 )
  466.         return;
  467.     CWK_SAVE_TEXT_POS();
  468.     if ( ! MON->WON ) {
  469.         MON->mon_win = CWK_MON_GET_WIN(next_monitor);
  470.         if ( MON->mon_win == -1 )
  471.             return;
  472.             CWK_MAKE_WINDOW( MON->title, MON->mon_win );
  473.         MON->WON = 1;
  474.     }
  475.  
  476.     /*
  477.         This statement because necessary when procedure monitoring
  478.         came in.  This is because the WON flag is not meaningful to
  479.         the monitoring, and we don't want to use the window if it
  480.         no longer exists.
  481.     */
  482.     if ( MON->mon_win == -1 )
  483.         return;
  484.  
  485.     _settextwindow(window[MON->mon_win].wind_coord.x1+1,
  486.         window[MON->mon_win].wind_coord.y1+1,
  487.         window[MON->mon_win].wind_coord.x2,
  488.         window[MON->mon_win].wind_coord.y2);
  489.     _settextposition(line,5);
  490.     _outtext(text_line);
  491.     CWK_RES_TEXT_POS();
  492. }
  493.  
  494. void CWK_CUR_LINE( MON, line, string )
  495. MON_REC_PTR MON;
  496. int line;
  497. char *string;
  498. {
  499.     if ( MON->WON == -1 )
  500.         return;
  501.     CWK_SAVE_TEXT_POS();
  502.     if ( ! MON->WON ) {
  503.         MON->mon_win = CWK_MON_GET_WIN(next_monitor);
  504.         if ( MON->mon_win == -1 )
  505.             return;
  506.             CWK_MAKE_WINDOW( MON->title, MON->mon_win );
  507.         MON->WON = 1;
  508.     }
  509.  
  510.     /*
  511.         This statement because necessary when procedure monitoring
  512.         came in.  This is because the WON flag is not meaningful to
  513.         the monitoring, and we don't want to use the window if it
  514.         no longer exists.
  515.     */
  516.     if ( MON->mon_win == -1 )
  517.         return;
  518.     
  519.     _settextwindow(window[MON->mon_win].wind_coord.x1+1,
  520.         window[MON->mon_win].wind_coord.y1+1,
  521.         window[MON->mon_win].wind_coord.x2,
  522.         window[MON->mon_win].wind_coord.y2);
  523.     _settextposition(line,1);
  524.     strncpy( string, string, 3);
  525.     _outtext(string);
  526.     CWK_RES_TEXT_POS();
  527. }
  528.  
  529. void CWK_DEL_WINDOW(int win_num)
  530. {
  531.     struct rccoord pos;
  532.     char format[80], buf[81];
  533.     int i;
  534.  
  535.     _settextwindow(window[win_num].wind_coord.x1, 
  536.         window[win_num].wind_coord.y1, window[win_num].wind_coord.x2, 
  537.         window[win_num].wind_coord.y2);
  538.  
  539.     sprintf(format,"%c-%ds",'%', ( window[win_num].wind_coord.y2 - 
  540.         window[win_num].wind_coord.y1) + 1 );
  541.     _setbkcolor(window[win_num].w -> bk);
  542.     _settextcolor(window[win_num].w -> co);
  543.     sprintf(buf,format," ");
  544.     for(i = 1; 
  545.         i <= (window[win_num].wind_coord.x2 -
  546.         window[win_num].wind_coord.x1 + 1); 
  547.         ++i) {
  548.             _settextposition(i, 1 );
  549.             _outtext(buf);
  550.         }
  551.     free(window[win_num].w);
  552. }
  553.  
  554. void print_license()
  555. {
  556.     AVL_WIN_PTR w;
  557.     int ch;
  558.  
  559.     w = AVL_MAKE_WINDOW( "License", 1,4,18,76, 1, 15);
  560.         _settextposition(1, 1);
  561.         _outtext("GWUMON Copyright (C) 1993 Charles W. Kann  & Michael Bliss Feldman \n");
  562.         _outtext("                          ckann@seas.gwu.edu mfeldman@seas.gwu.edu \n");
  563.         _outtext( "This program is free software; you can redistribute it and/or modify\n" );
  564.         _outtext( "it under the terms of the GNU General Public License as published by\n" );
  565.         _outtext( "the Free Software Foundation; either version 2 of the License, or\n" );
  566.         _outtext( " any later version. \n\n" );
  567.  
  568.         _outtext( "This program is distributed in the hope that it will be useful,\n" );
  569.         _outtext( "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" );
  570.         _outtext( "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" );
  571.         _outtext( "GNU General Public License for more details.\n\n" );
  572.  
  573.         _outtext( "You should have received a copy of the GNU General Public License\n" );
  574.         _outtext( "along with this program; if not, write to the Free Software\n" );
  575.         _outtext( "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n" );
  576.  
  577.     ch = getch();
  578.     AVL_DEL_WINDOW( w );
  579.  
  580. }
  581.  
  582. /*************************************************************************
  583. *
  584. *    This section of code prints out any help type screens (ie. ones
  585. *    which just give straight text in a window which is put up for
  586. *    a single clock cycle.
  587. *
  588. *************************************************************************/
  589.  
  590. void print_setup_help()
  591. {
  592.     AVL_WIN_PTR w;
  593.     int ch;
  594.  
  595.     w = AVL_MAKE_WINDOW( "Setup Help", 3,5,22,75, 1, 15);
  596.         _settextposition(1, 1);
  597.     _outtext("The following can be set from the setup Screen                     \n");
  598.         _outtext("Delay Rate - This is the amount to delay the monitor on each clock \n");
  599.         _outtext("             cycle. Note that a clock cycle is one pass through    \n");
  600.         _outtext("             the interpreter.                                      \n");
  601.         _outtext("Cycles for Reporting Exec % - If Type of Monitoring is Exec %, then\n");
  602.         _outtext("             this tells how many cycles to run between reporting\n");
  603.     _outtext("Delay time - If the Type of Delay is set to Scaled then this is \n");
  604.     _outtext("             the number of clock ticks to be interpreted as     \n");
  605.     _outtext("             1 second                                           \n");
  606.     _outtext("RR statments - If Type of Tasking is set to Round Robin, then   \n");
  607.     _outtext("             this is the number of cycles between task switches \n");
  608.     _outtext("Type of Tasking - This is the task type model.  It can be set   \n");
  609.     _outtext("             to Round Robin or Run Til Blocked                  \n");
  610.     _outtext("Type of Delay - The type of delay can be either Real ( 1 second \n");
  611.     _outtext("             is a real time second), or Scaled ( 1 second is    \n");
  612.     _outtext("             some number of clock cycles                         \n");
  613.     ch = getch();
  614.     _outtext("Type of Monitoring - This can be either None (No monitoring is   \n");
  615.     _outtext("             used), Line (show the lines of code as they are     \n");
  616.     _outtext("             executed ),  or Exec % (show the execution % for    \n");
  617.     _outtext("             each task at the interval specified above)          \n");
  618.     _outtext("Line Trace - Turns Line Tracing on.  This stops the monitor after\n");
  619.     _outtext("             each line on the current monitor screen is executed \n");
  620.     _outtext("Task Trace - Turns Task Tracing on.  This stops the monitor after\n");
  621.     _outtext("             each task switch for a task on the current monitor  \n");
  622.     _outtext("             screen.                                             \n");
  623.     _outtext("Type of Monitoring Window - Type of window to use  in Line       \n");
  624.     _outtext("             Monitoring Mode.  You can show 1 - 4 tasks in       \n");
  625.     _outtext("             4 different ways.      \n");
  626.  
  627.     ch = getch();
  628.     AVL_DEL_WINDOW( w );
  629. }
  630.  
  631. void print_help()
  632. {
  633.     AVL_WIN_PTR w;
  634.     int ch;
  635.  
  636.     w = AVL_MAKE_WINDOW( "Help", 5,15,18,70, 1, 15);
  637.         _settextposition(1, 1);
  638.         _outtext("Up Arr - increase speed    Dn Arr - decrease speed\n");
  639.         _outtext("ctrl l - line step         ctrl h - help screen\n");
  640.         _outtext("ctrl t - task step         ctrl a - control screen\n");
  641.         _outtext("ctrl b - stop monitoring   ctrl d - setup screen\n");
  642.         _outtext("ctrl r - resize window \n");
  643.         _outtext("ctrl c or ESC - stop the execution of the monitor\n\n");
  644.         _outtext("Status Codes \n");
  645.         _outtext("R - Wait on Rendezvous      M - Rendezvous Meet\n");
  646.         _outtext("D - Wait on Delay           * - Task Ready to Run\n");
  647.         _outtext("--> Task currently running ");
  648.  
  649.     ch = getch();
  650.     AVL_DEL_WINDOW( w );
  651.     
  652. }
  653.  
  654. /***********************************************************************/
  655. /*   Control Window code is contained here.                            */
  656. /***********************************************************************/
  657.  
  658. static AVL_WIN_PTR Control_Window;
  659. CWK_CONTROL_TASK( Schedule_Type, Task_Type, Execution_Time, Report_Time )
  660. char *Schedule_Type, *Task_Type;
  661. int Execution_Time, Report_Time;
  662. {
  663.     char msg[100];
  664.  
  665.     CWK_SAVE_TEXT_POS();
  666.     Control_Window = AVL_MAKE_WINDOW( "Task Control -- use t to toggle task, Esc to quit", 12, 5, 24, 75, 1, 15);
  667.         _settextposition(1, 1);
  668.         sprintf(msg, "Scheduling : %s        Current task : %s\n",
  669.             Schedule_Type, Task_Type );
  670.         _outtext(msg);
  671.         sprintf(msg, "Execution Time : %5d   Time to Report: %5d\n", 
  672.         Execution_Time, Report_Time );
  673.         _outtext(msg);
  674. }
  675.  
  676. CWK_PRINT_CONTROL_LINE( iline, msg )
  677. int iline;
  678. char *msg;
  679. {
  680.     _settextposition(iline, 1);
  681.     _outtext(msg);
  682.     _settextposition(iline, 1);
  683. }
  684. CWK_DEL_CONTROL ()
  685. {
  686.     AVL_DEL_WINDOW( Control_Window );
  687.     CWK_RES_TEXT_POS();
  688. }
  689.  
  690. /***********************************************************************/
  691. /*   Exception Reports are printed out here                   */
  692. /***********************************************************************/
  693.  
  694. CWK_Report_Exception( task_name, msg )
  695. char *task_name, *msg;
  696. {
  697.     char msg1[80];
  698.     AVL_WIN_PTR Win;
  699.     CWK_SAVE_TEXT_POS();
  700.     Win = AVL_MAKE_WINDOW( "Exception Raised", 6, 1, 11, 80, 1, 15);
  701.         _settextposition(2, 1);
  702.     sprintf( msg1, "Exception Raised in task name %s\n", task_name );
  703.     _outtext( msg1 );
  704.     _outtext( msg );
  705.     getch();
  706.     AVL_DEL_WINDOW( Win );
  707.     CWK_RES_TEXT_POS();
  708.     
  709. }
  710.  
  711. /***********************************************************************/
  712. /*   Execution Pct Report is contained here                            */
  713. /***********************************************************************/
  714.  
  715. CWK_REPORT_TIME( execution_time )
  716. long execution_time;
  717. {
  718.     char msg[100];
  719.     int i, start;
  720.     static int save_step_rate;
  721.  
  722.     if (save_step_rate == step_rate )
  723.     {
  724.         save_step_rate = step_rate;
  725.         return;
  726.     }
  727.     CWK_SAVE_TEXT_POS();
  728.     _settextwindow(24,35,24,79);
  729.     start = 16 - step_rate ;
  730.         _settextposition(1, 1);
  731.     sprintf( msg, "Speed " );
  732.     _outtext( msg );
  733.     for ( i = 7; i < start; ++i )
  734.     {
  735.             _settextposition(1, i);
  736.         _outtext( "=" );
  737.     }
  738.  
  739.     for ( i = start; i <= 15; ++i )
  740.     {
  741.             _settextposition(1, i);
  742.         _outtext( "." );
  743.     }
  744. #if 0
  745.         _settextposition(1, 20);
  746.     sprintf( msg, "Cycles Exec %d", execution_time );
  747.     _outtext( msg );
  748. #endif
  749.     CWK_RES_TEXT_POS();
  750. }
  751.  
  752. /***********************************************************************/
  753. /*   Execution Pct Window code is contained here.                      */
  754. /***********************************************************************/
  755.  
  756. static AVL_WIN_PTR Exec_Pct_Window;
  757. static int Exec_WON = 0;
  758. CWK_EXEC_PCT()
  759. {
  760.     char msg[100];
  761.     
  762.     if ( Exec_WON )
  763.         return;
  764.     Exec_WON = 1;
  765.  
  766.     CWK_SAVE_TEXT_POS();
  767.     Exec_Pct_Window = AVL_MAKE_WINDOW( "Exec Pct Viewer -- Use Ctrl-B to quit", 12, 1, 24, 80, 1, 15);
  768.     _settextwindow(13,2,23,79);
  769.         _settextposition(1, 1);
  770.     sprintf( msg, " #  Name    St  %c   #  Name    St  %c   #  Name    St  %c   #  Name    St  %c " , '%', '%', '%', '%'); 
  771.     _outtext( msg );
  772.     CWK_RES_TEXT_POS();
  773. }
  774.  
  775.  
  776. CWK_EXEC_PRINT_LINE( line, msg )
  777. int line;
  778. char *msg;
  779. {
  780.     CWK_SAVE_TEXT_POS();
  781.     _settextwindow(13,2,23,79);
  782.         _settextposition(line, 1);
  783.     _outtext( msg );
  784.     CWK_RES_TEXT_POS();
  785. }
  786.  
  787. CWK_DEL_EXEC_PCT()
  788. {
  789.     CWK_SAVE_TEXT_POS();
  790.     AVL_DEL_WINDOW( Exec_Pct_Window );
  791.     Exec_WON = 0;
  792.     CWK_RES_TEXT_POS();
  793. }
  794.  
  795. /***********************************************************************
  796. *
  797. *    This section of code initializes the monitor windows.  It puts
  798. *    the windows on the screen, and sets up the structures so that
  799. *    they can be used by the CUR_LINE and WRITE_LINE routines.
  800. *
  801. ***********************************************************************/
  802.  
  803. CWK_SETUP_WINDOWS()
  804. {
  805.     int i; 
  806.  
  807.     for ( i = 0; i < MAX_WINDOWS; ++i) 
  808.         window[i].used = 0;
  809.     
  810.     /*
  811.         Procedure monitoring.  The windows are inset one row and
  812.         column as the procedures continue down.
  813.     */
  814.     if ( ! task_monitor )
  815.     {
  816.         /*
  817.         For procedure monitoring, set up the windows based on the
  818.         whether the Large_Monitor (ie, the monitor is 20 lines) or
  819.         small monitor (ie. the monitor is 13 lines) is choosen.
  820.  
  821.         Note that the SAVE_WIN_SIZE is 1 larger than the maximum
  822.         window size.  This is because the first window has a block
  823.         level of 1, and will thus make the WIN_SIZE =SAVE_WIN_SIZE -1
  824.         */
  825.         if ( Large_Monitor )
  826.         {
  827.             Windows_Used = 12;
  828.         SAVE_WIN_SIZE = 19;
  829.         ROWS = 3;
  830.         }
  831.         else
  832.         {
  833.             Windows_Used = 5;
  834.             SAVE_WIN_SIZE = 12;
  835.         ROWS = 10;
  836.         }
  837.         LINE_SIZE = 68;
  838.  
  839.         if ( Large_Monitor )
  840.         {
  841.             for ( i = 0; i < MAX_WINDOWS; ++i) 
  842.             {
  843.             window[i].wind_coord.x1 = 5+i; window[i].wind_coord.y1 = 1;
  844.             window[i].wind_coord.x2 = 24; window[i].wind_coord.y2 = 80-i;
  845.             }
  846.         }
  847.         else
  848.         {
  849.             for ( i = 0; i < MAX_WINDOWS; ++i) 
  850.             {
  851.             window[i].wind_coord.x1 = 12+i; window[i].wind_coord.y1 = 1;
  852.             window[i].wind_coord.x2 = 24; window[i].wind_coord.y2 = 80-i;
  853.             }
  854.         }
  855.     }
  856.  
  857.     /*
  858.         Task monitoring windows.  This sets up the four types of
  859.         task windows.  The definition of the windows is completely
  860.           done here, and this should be all that is needed to change
  861.         to change the sizes or definitions of the windows.  NOTE:
  862.         You will have to change the MONITOR definition (ie. the
  863.         ROWS define) if you are going to increase the size of the
  864.         monitor windows.
  865.     */
  866.     else
  867.     {
  868.         switch ( monitor_window_type ) {
  869.             case 0 :
  870.             Windows_Used = 4;
  871.             WIN_SIZE = 5;
  872.             LINE_SIZE = 28;
  873.             window[0].wind_coord.x1 = 12; window[0].wind_coord.y1 = 1;
  874.             window[0].wind_coord.x2 = 18; window[0].wind_coord.y2 = 40;
  875.             window[1].wind_coord.x1 = 12; window[1].wind_coord.y1 = 41;
  876.             window[1].wind_coord.x2 = 18; window[1].wind_coord.y2 = 80;
  877.             window[2].wind_coord.x1 = 18; window[2].wind_coord.y1 = 1;
  878.             window[2].wind_coord.x2 = 24; window[2].wind_coord.y2 = 40;
  879.             window[3].wind_coord.x1 = 18; window[3].wind_coord.y1 = 41;
  880.             window[3].wind_coord.x2 = 24; window[3].wind_coord.y2 = 80;
  881.             break;
  882.  
  883.            case 1 :
  884.             Windows_Used = 2;
  885.             WIN_SIZE = 5;
  886.             LINE_SIZE = 68;
  887.             window[0].wind_coord.x1 = 12; window[0].wind_coord.y1 = 1;
  888.             window[0].wind_coord.x2 = 18; window[0].wind_coord.y2 = 80;
  889.             window[1].wind_coord.x1 = 18; window[1].wind_coord.y1 = 1;
  890.             window[1].wind_coord.x2 = 24; window[1].wind_coord.y2 = 80;
  891.             break;
  892.     
  893.             case 2 :
  894.             Windows_Used = 2;
  895.             WIN_SIZE = 11;
  896.             LINE_SIZE = 28;
  897.             window[0].wind_coord.x1 = 12; window[0].wind_coord.y1 = 1;
  898.             window[0].wind_coord.x2 = 24; window[0].wind_coord.y2 = 40;
  899.             window[1].wind_coord.x1 = 12; window[1].wind_coord.y1 = 41;
  900.             window[1].wind_coord.x2 = 24; window[1].wind_coord.y2 = 80;
  901.             break;
  902.  
  903.             case 3 :
  904.             Windows_Used = 1;
  905.             WIN_SIZE = 11;
  906.             LINE_SIZE = 68;
  907.             window[0].wind_coord.x1 = 12; window[0].wind_coord.y1 = 1;
  908.             window[0].wind_coord.x2 = 24; window[0].wind_coord.y2 = 80;
  909.             break;
  910.  
  911.             default :
  912.             printf( "invalid use of monitor window types\n" );
  913.             break;
  914.         }
  915.     }
  916. }
  917.  
  918. /*
  919. *    This routine resizes the windows.  It takes space from the output 
  920. *    window to be used by the monitor windows.  It reallocates the space,
  921. *    and then clears the output window (since I don't know what is in
  922. *    it).
  923. */
  924.  
  925. CWK_Resize_Window()
  926. {
  927.     CWK_ERASE_ALL_MON_WIN();
  928.     AVL_DEL_WINDOW( output_win );
  929.     CWK_SETUP_WINDOWS();
  930.     output_win = AVL_MAKE_WINDOW( " GWU ADA MONITOR - Type Ctrl h for help, ESC to leave", 1, 1, ROWS+1, 80, 1, 15 );
  931.  
  932. }
  933.  
  934.